package com.lzk.springboot.demo.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@ConditionalOnProperty(prefix = "swagger",value = {"enable"},havingValue = "true")
@EnableSwagger2
public class SwaggerConfig {
    private boolean enableSwagger = true;

/*
 这个方法的返回值交给Spring 管理
 */
 @Bean
 public Docket petApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .select()
 //哪些包需要生成文档
 .apis(RequestHandlerSelectors.basePackage("com.lzk.springboot.demo.controller")) //指定提供接口所在的基包
 .build();
 }
 /**
  * 该套 API 说明，包含作者、简介、版本、host、服务URL
  * @return
  */
         private ApiInfo apiInfo() {
 return new ApiInfoBuilder()
 .title("文章title")
 .contact(new Contact("hmtest", "", "hm@域名反写"))
 .version("版本")
 .description("API")
 .build();
 }
}
